<?php
/**
 * 加群小程序相关接口
 * 作者：刘单风
 * 最后修改时间：2019-01-16
 * 版权：医库PHP小组
 */
namespace app\groupapi\controller;

use app\model\Wechatgroups;

class Groups extends Apibase
{

    /**
     * 微信群列表数据
     * @param $depid 二级科室id
     * @param $fdepid 父级科室id
     * @param $cityid 城市id
     * @param $proid 省id
     * @param $keywords 搜索关键词
     */
    public function groupList()
    {
        $depid = input('depid', 0);
        $fdepid = input('fdepid', 0);
        $cityid = input('cityid', 0);
        $provid = input('provid', 0);
        $keywords = input('keywords', "");
        $cpage = input('cpage', 1);
        $disid = input('disid', 0);
        $datatype = input('datatype', 0);
        $groupModel = new Wechatgroups();
        $where = "data_type=$datatype";
        if ($depid) {
            $where .= " AND dep_id=$depid";
        }
        if ($cityid) {
            $where .= " AND city_id=$cityid";
        }
        if ($provid) {
            if ($provid == -1) {
                $where .= " AND prov_id=0";
            }else{
                $where .= " AND prov_id=$provid";
            }
        }
        if ($keywords) {
            $where .= " AND group_name LIKE '%$keywords%'";
        }
        if ($fdepid) {
            //获取子集科室
            $childids = $groupModel->childdeps($fdepid);
            $where .= " AND dep_id IN($childids)";
        }
        if ($datatype && $disid) {
            $where .= " AND dis_id=$disid";
        }
        $data = $groupModel->groupList($where, $cpage);
        return parent::respond($data);
    }

    /**
     * 科室数据信息
     */
    public function depList()
    {
        $datatype=input('datatype',0);
        $groupModel = new Wechatgroups();
        $depdata = $groupModel->deplist($datatype);
        return parent::respond($depdata);
    }

    /**
     * 城市数据信息
     */
    public function cityList()
    {
        $groupModel = new Wechatgroups();
        $citydata = $groupModel->citylist();
        return parent::respond($citydata);
    }

    /**
     * 热门微信群
     */
    public function hotList()
    {
        $datatype = input('datatype', 0);
        $groupModel = new Wechatgroups();
        $data = $groupModel->groupList("is_hot=1 AND data_type=$datatype",1);
        return parent::respond($data);
    }

    /**
     * 群二维码详情链接
     */
    public function groupDetail($groupid,$datatype)
    {
        $groupModel = new Wechatgroups();
        $data = $groupModel->groupDetail($groupid);
        $this->assign('groudetail', $data);
        $this->assign('datatype', $datatype);
        return $this->fetch('group_detail');
    }

    /**
     * banner数据信息
     */
    public function bannerList()
    {
        $datatype = input('datatype', 0);
        $groupModel = new Wechatgroups();
        $data = $groupModel->bannerdata($datatype);
        return parent::respond($data);
    }
}